package com.example.myapplication.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.myapplication.MainActivity;
import com.example.myapplication.R;
import com.example.myapplication.layout.LineLayoutActivity;
import com.example.myapplication.util.ToastUtil;

public class FragmentFA extends Fragment {

    public interface messageClick{
        String onClick(String data);
    }

    //定义回调接口
    public interface MyListener{
        void sendValue(String value);
    }

    private MyListener myListener;

    @Override
    public void onAttach(Context context) {
        //将Activity为listener赋值
        super.onAttach(context);
        myListener = (MyListener) getActivity();
    }


    public FragmentFA() {

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_f_a, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {

        view.findViewById(R.id.smart).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TextView msg = view.findViewById(R.id.write);
                String s = msg.getText().toString();
                myListener.sendValue(s);
            }
        });
        super.onViewCreated(view, savedInstanceState);
    }
}